/**
 * 
 */
package monitor;

import java.net.InetAddress;
import java.util.UUID;

/**
 * @author Robbie
 *
 */
public class RemoteHost {
	
	private InetAddress hostAddress;
	private int listenerPort;
	private int status; // 3=strong 2=weak 1=dead
	private int missedMessages;
	private UUID myID;
	
	public RemoteHost(InetAddress host, int port, String uuid){
		hostAddress = host;
		listenerPort = port;
		status = 3;
		missedMessages = 0;
		myID = UUID.fromString(uuid);
	}
	
	public synchronized int getPort(){
		return listenerPort;
	}
	
	public synchronized InetAddress getAddress(){
		return hostAddress;
	}
	
	public synchronized int getStatus(){
		return status;
	}
	
	public synchronized void decreaseStatus(){
		if(status>1)status--;
	}
	
	public synchronized void increaseStatus(){
		if(status<3)status++;
	}
	
	public String toString(){
		return hostAddress.getHostAddress()+new String(":"+listenerPort+":")+myID.toString();
	}
	
	public synchronized UUID getUUID(){
		return myID;
	}
	
	public synchronized boolean equals(RemoteHost r){
//		if(hostAddress.equals(r.getAddress())&&listenerPort==r.getPort()){
//			return true;
//		}
		if(r.getUUID().equals(myID)){
			return true;
		}
		return false;
	}
	
	public synchronized boolean equals(InetAddress ip, int port){
		if(hostAddress.equals(ip)&&listenerPort==port){
			return true;
		}
		return false;
	}
	
	public synchronized void increaseMessagesMissed(){
		missedMessages++;
	}
	
	public synchronized int numberOfMissedMessages(){
		return missedMessages;
	}
	
	public synchronized void resetMissedMessages(){
		missedMessages = 0;
	}

}
